package cn.wolfcode.car.base.service.impl;

import cn.wolfcode.car.base.domain.MyUser;
import cn.wolfcode.car.base.mapper.MyUserMapper;
import cn.wolfcode.car.base.query.MyUserQuery;
import cn.wolfcode.car.base.service.IMyUserService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.util.Convert;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional
public class MyUserServiceImpl implements IMyUserService {

    @Autowired
    private MyUserMapper myUserMapper;


    @Override
    public TablePageInfo<MyUser> query(MyUserQuery qo) {
        PageHelper.startPage(qo.getPageNum(), qo.getPageSize());
        return new TablePageInfo<MyUser>(myUserMapper.selectForList(qo));
    }


    @Override
    public void save(MyUser myUser) {
        myUserMapper.insert(myUser);
    }

    @Override
    public MyUser get(Long id) {
        return myUserMapper.selectByPrimaryKey(id);
    }


    @Override
    public void update(MyUser myUser) {
        myUserMapper.updateByPrimaryKey(myUser);
    }

    @Override
    public void deleteBatch(String ids) {
        Long[] dictIds = Convert.toLongArray(ids);
        for (Long dictId : dictIds) {
            myUserMapper.deleteByPrimaryKey(dictId);
        }
    }

    @Override
    public List<MyUser> list() {
        return myUserMapper.selectAll();
    }

}
